<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>侦听器</title>
    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        body {
            padding: 30px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <input type="text" v-model="view">
        </div>
        <div v-if="show_view[0]" class="box1">
            <h1>待机界面</h1>
        </div>
        <div v-if="show_view[1]" class="box2">
            <h1>主界面</h1>
        </div>
        <div v-if="show_view[2]" class="box3">
            <h1>输入密码</h1>
        </div>
        <div v-if="show_view[3]" class="box3">
            <h1>取款</h1>
        </div>
        <div v-if="show_view[4]" class="box3">
            <h1>查看余额</h1>
        </div>
    </div>


</body>
<script src=" https://cdn.jsdelivr.net/npm/vue@2.6.14">
</script>
<script>

    // 实例化Vue对象
    let app = new Vue({
        el: '#app',         // Vue对象在页面中的作用容器
        // 当前Vue对象设置的默认数据
        data: {
            view: 0,
            waite: true,
            main: false,
            password: false,
            show_view: []
        },
        // 使用生命周期
        beforeCreate: function () {
            // this.test()
            setTimeout(() => {
                this.view = 1
            }, 1000)
        },
        mounted: function () {
            for (let i = 0; i < 5; i++) {
                this.show_view.push(0)
            }
            this.show_view[this.view] = 1




        },

        // methods是当前应用定义的函数方法
        methods: {

        },
        // 计算属性
        computed: {

        },
        // 侦听器
        watch: {
            view: function (newVal, oldVal) {
                console.log('新值：', newVal)
                console.log('旧值：', oldVal)

                // this.waite = false
                // this.main = false
                // this.password = false

                // newVal *= 1
                // switch (newVal) {
                //     case 0:
                //         this.waite = true
                //         break

                //     case 1:
                //         this.main = true
                //         break

                //     case 2:
                //         this.password = true
                //         break
                // }


                for (let i = 0; i < this.show_view.length; i++) {
                    this.show_view[i] = 0
                }

                this.show_view[this.view] = 1
            }
        }


    })


</script>

</html>